package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/setmeal")
@Slf4j
@Api(tags = "套餐管理接口")
public class SetmealController {
    @Autowired
    private SetmealService setmealService;
    @ApiOperation("套餐分页查询")
    @GetMapping("/page")
    public Result PackagePaginationQuery(SetmealPageQueryDTO setmealPageQueryDTO){
        PageResult pageResult = setmealService.PackagePaginationQuery(setmealPageQueryDTO);
        return Result.success(pageResult);
    }
    @ApiOperation("添加套餐")
    @PostMapping()
    public Result AddPackage(@RequestBody SetmealDTO setmealDTO){
        setmealService.AddPackage(setmealDTO);
        return Result.success();
    }
    @ApiOperation("根据ID查询套餐")
    @GetMapping("/{id}")
    public Result idQuery(@PathVariable("id") String id){
        SetmealVO setmealVO = setmealService.idQuery(id);
        return Result.success(setmealVO);
    }
    @ApiOperation("修改套餐")
    @PutMapping()
    public Result changePackage(@RequestBody SetmealDTO setmealDTO){
        setmealService.changePackage(setmealDTO);
        return Result.success();
    }
    @ApiOperation("套餐起售、停售")
    @PostMapping("/status/{status}")
    public Result SetmealStateChange (@PathVariable("status") String status, String id){
        String s = setmealService.SetmealStateChange(status, id);
        if (s == null)
             return Result.success();
        else
            return Result.error(s);
    }
    @ApiOperation("批量删除套餐")
    @DeleteMapping()
    public Result DeletSetmeal(Integer[] ids){
        String s = setmealService.DeletSetmeal(ids);
        if (s == null)
            return Result.success();
        else
            return Result.error(s);
    }
}
